<template>
  <view class="container">
    <view class="example">
      <uni-forms ref="form" :model="PigBreeList" labelWidth="80px">
        <uni-forms-item label="母猪耳号" name="pigCode">
          <uni-easyinput v-model="PigBreeList.pigCode" placeholder="请输入猪只耳号" />
        </uni-forms-item>
        <uni-forms-item label="公猪耳号" name="pigFatherCode">
          <uni-easyinput v-model="PigBreeList.pigFatherCode" placeholder="请输入公猪耳号" />
        </uni-forms-item>

        <uni-forms-item label="配种方式" name="pigBreedType" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="PigBreeList.pigBreedType"
			 :localdata="pigBreedTypes"
			 @change="change">
			 </uni-data-select>
        </uni-forms-item>
		<uni-forms-item label="配种管理员" name="pigBreedManager" required>
			<!-- 下拉框选择 -->
			<uni-data-select
			 v-model="PigBreeList.pigBreedManager"
			 :localdata="staffNameList">
			 </uni-data-select>
		</uni-forms-item>
		<view class="example-body">
			<uni-forms-item label="配种时间" name="pigBreedTime">
			  <uni-datetime-picker type="datetime" v-model="PigBreeList.pigBreedTime" @change="changeLog" />
			</uni-forms-item>
		</view>
      </uni-forms>
      <button type="primary" @click="submit">提交</button>
    </view>
  </view>
</template>

<script>


import { listPigBreed,getPigBreed, findAllStaffName,delPigBreed, addPigBreed, updatePigBreed} from "@/api/hmy/pigBreed";


export default {
  name: "PigBreed",
  // dicts: ['hmy_pig_breed_type'],
  data() {
    return {

		PigBreeList: {
			pigCode: "",
			pigFatherCode: "",
			pigBreedTime: ""

		},


		pigBreedTypes: [{
		  text: ' 人工授精',
		  value: "1"
		},
		{
		  text: ' 自然交配',
		  value: "2"
		}],
		rules: {
		  pigCode: {
			rules: [{
			  required: true,
			  errorMessage: '猪只耳号不能为空'
			}]
		  }
	    },
		//所有猪只配种负责人
		staffNameList: [],
	}
  },
	created() {

		findAllStaffName().then(response => {
			var staffList = response.data;
			staffList.forEach(item => {
				this.staffNameList.push({
					'text': item.staffName,
					'value': item.staffId
				})
			})
		})
	},

  onReady() {
    this.$refs.form.setRules(this.rules)
  },
  methods: {
	  	change(e) {
	  				this.single = e
	  				console.log('change事件:', this.single = e);
	  			},
	  	changeLog(e) {
	  				console.log('change事件:', e);
	  			},

    submit(ref) {
      this.$refs.form.validate().then(res => {
        addPigBreed(this.PigBreeList).then(response => {
          this.$modal.msgSuccess("新增成功")
		  //成功后返回页面
		  this.$tab.navigateTo('/pages/hmy/pigBreed/index');
        })
      })
    }
  }
}
</script>

<style lang="scss">

  /* #ifndef APP-NVUE */
  page {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    min-height: 100%;
    height: auto;
	background-color: #fcfcfc;
  }

  view {
    font-size: 16px;
    line-height: inherit;
  }
  /* #endif */
  .code{
	margin-bottom :5px;
  }
  .icon{
	float:right;
	margin-right:10px;
	margin-top :5px;
  }
  .message{
	margin-top:5px;
	color: #989897;
	line-height: 25px;
  }


  .example {
    padding: 15px;
    background-color: #fff;
  }

  .segmented-control {
    margin-bottom: 15px;
  }

  .button-group {
    margin-top: 15px;
    display: flex;
    justify-content: space-around;
  }

  .form-item {
    display: flex;
    align-items: center;
    flex: 1;
  }

  .button {
    display: flex;
    align-items: center;
    height: 35px;
    line-height: 35px;
    margin-left: 10px;
  }
</style>

